package com.studydemo.controller;

import com.studydemo.dao.entity.Book;
import com.studydemo.service.MongoDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author 无与伦比
 * @version 1.0
 * @date 2021/2/23 23:40
 */
@RestController
@RequestMapping("/mongodb/")
public class MongoDbController {

    @Autowired
    private MongoDbService mongoDbService;

    @PostMapping("/mongosavebook")
    public String saveObj() {
        Book book = new Book();
        book.setId("1");
        book.setInfo("1234444");
        book.setCreateTime(new Date());
        book.setName("1111111111111");
        book.setPrice(2);
        book.setPublish("wwwwwwwwww");
        book.setUpdateTime(new Date());
        List<Book>list = mongoDbService.findAll();

        mongoDbService.save(book);
        return "ok";
    }
}
